package com.cpc.mback.controller;


import com.cpc.mback.RespEntity;
import com.cpc.mback.entity.User;
import com.cpc.mback.service.MainService;
import com.cpc.mback.service.RecordService;
import com.cpc.mback.service.UploadService;
import com.cpc.mback.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "咨询接口", tags = "咨询接口", description = "没有description")
@RequestMapping("/api/consult")
public class ConsultController {

    @Autowired
    MainService mainService;

    @Autowired
    UploadService uploadService;
    @Autowired
    RecordService recordService;
    @Autowired
    UserService userService;


    @ApiOperation(value = "fetch用户信息", notes = "参数 openId\n" +
            " ")
    @GetMapping("/fetch")
    public ResponseEntity fetchUser(@RequestParam String openId) {
        //return userService.fetchUser(openId);
        return ResponseEntity.status(200).body(RespEntity.code(200).body(userService.fetchUser(openId)).build());
    }

    @ApiOperation(value = "fetch所有用户信息", notes = "参数 openId\n" +
            " ")
    @GetMapping("/fetch-all")
    public ResponseEntity fetchAllUser(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer size) {
        //return userService.fetchUser(openId);
        return ResponseEntity.status(200).body(RespEntity.code(200).body(userService.fetchAllUser(PageRequest.of(page - 1, size))).build());
    }

    @ApiOperation(value = "fetch所有用户信息", notes = "参数 openId\n" +
            " ")
    @GetMapping("/sort")
    public ResponseEntity Sort(@RequestParam String Sort,@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer size) {
        //return userService.fetchUser(openId);
        return ResponseEntity.status(200).body(RespEntity.code(200).body(userService.Sort(Sort,PageRequest.of(page - 1, size))).build());
    }


}
